package com.dj.dormitory.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dj.dormitory.entity.Student;
import com.dj.dormitory.entity.req.StuReq;
import com.dj.dormitory.entity.vo.StuVo;
import com.dj.dormitory.mapper.StudentMapper;
import com.dj.dormitory.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author DJ同学
 * @since 2021-01-24
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Override
    public List<StuVo> getAll() {

        return this.baseMapper.getAllStu();
    }

    @Override
    public Map<String, Object> getList(StuReq stuReq) {
        Page<StuVo> page = new Page<>(stuReq.getPage(),stuReq.getLimit());
        List<StuVo> list = this.baseMapper.getStuPageList(page,stuReq);
        Map<String,Object> map = new HashMap();
        map.put("count",page.getTotal());
        map.put("stus",list);
        return map;
    }

    @Override
    public StuVo getOneByUserId(Integer userId) {
        StuVo stuVo = this.baseMapper.getOneByUserId(userId);
        return stuVo;
    }

    @Override
    public Integer getSIdByUserId(Integer userId) {
        StuVo stuVo = this.baseMapper.getOneByUserId(userId);
        return stuVo.getId();
    }
}
